<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.soeasy.util.UserUtil"%>
<%@page import="com.feib.soeasy.model.Payment"%>

<c:choose>
	<c:when test="${null != actionBean.resultPayment}">
		<table id="paymentListTable">
				<tr>
					<c:choose>
						<c:when test="${2 == actionBean.resultPayment.group.groupType}">
							<th>學號</th>
							<td><c:out value="${actionBean.resultPayment.studentId}"/></td>
						</c:when>
						<c:otherwise>
							<th>客戶編號</th>
							<td><c:out value="${actionBean.resultPayment.payerId}"/></td>
						</c:otherwise>
					</c:choose>	
					
					<th>姓名</th>
					<td><c:out value="${actionBean.resultPayment.payerName}"/></td>
					<th>繳費帳號</th>
					<td><c:out value="${actionBean.resultPayment.virtualAccount}"/></td>
				</tr>
				<tr>
					<td colspan="6">
						<table>	
							<tr>
								<td colspan="6" class="paymentHeader">
									<c:out value="${actionBean.resultPayment.paymentName}"/></td>
							</tr>
							<tr>
								<th>繳費帳號</th>
								<td><c:out value="${actionBean.resultPayment.virtualAccount}"/></td>
								<th>姓名</th>
								<td><c:out value="${actionBean.resultPayment.payerName}"/></td>
								<th>應繳金額</th>
								<td align="right"><fmt:formatNumber value="${actionBean.resultPayment.totalAmount}" pattern="##,###" /></td>
							</tr>
							<tr>
								<th>繳費期限</th>
								<td align="center"><fmt:formatDate value="${actionBean.resultPayment.payDue}" pattern="yyyy/MM/dd"/></td>
								<th>繳費日期</th>
								<td align="center">
									<c:if test="${5 == actionBean.resultPayment.paymentStatus}">
										<fmt:formatDate value="${actionBean.resultPayment.writeOffPayment.writeOffDate}" pattern="yyyy/MM/dd"/>
									</c:if>
								</td>
								<th>繳費金額</th>
								<td align="right">
									<c:if test="${5 == actionBean.resultPayment.paymentStatus}">
										<fmt:formatNumber value="${actionBean.resultPayment.writeOffPayment.amount}" pattern="##,###" />
									</c:if>
								</td>
							</tr>
							<tr>
								<th colspan="6">繳費明細</th>
							</tr>
							<c:set var="old" value="${true}"/>
							<c:forEach items="${actionBean.resultPayment.paymentItems}" var="paymentItem" varStatus="rowstat1">
							<c:if test="${paymentItem.amount != 0 }">
								<c:if test="${old}"><tr></c:if>
									<th><c:out value="${paymentItem.itemName}"/></th>
									<td colspan="2" align="right"><fmt:formatNumber value="${paymentItem.amount}" pattern="##,###" /></td>
									<c:if test="${not old}"> </tr> </c:if>
								<c:set var="old" value="${not old }"/>
							</c:if>
							</c:forEach>
							<%//old == flase =>基數個，需要再補空白欄位與結束符號 %>
							<c:if test="${not old}"><th>&nbsp;</th><td colspan="2">&nbsp;</td></tr></c:if>
						</table>
					</td>
				</tr>
							<!-- 原因 -->
				<c:if test="${(null != actionBean.resultPayment.writeOffPayment.writeOffNote )||(null != actionBean.resultPayment.paymentCanceled.cancelReason ) }">						
					 <tr>	
							<c:choose>
						      <c:when test="${5 == actionBean.resultPayment.paymentStatus }">
							    <th>銷帳原因</th>
							    <td align="left" colspan="6">
										<c:out  value= "${actionBean.resultPayment.writeOffPayment.writeOffNote}" />
							</td>
						      </c:when>
						      <c:when test="${4 == actionBean.resultPayment.paymentStatus }">
							    <th>註銷原因</th>
							       <td align="left" colspan="6">
										<c:out  value= "${actionBean.resultPayment.paymentCanceled.cancelReason}" />
							</td>
						      </c:when>
							<c:otherwise></c:otherwise>
					</c:choose>	
						
							
						</tr>
				</c:if>
				<tr>
					<td colspan="6" class="formBtnGroup">
						<input type="button" id="printBtn3" value="列印" />
						<input type="button" id="closeBtn3" value="離開" />
					</td>
				</tr>
		</table>			
		<script type="text/javascript">
		<!--
		$(document).ready(function() {			
			$( "#paymentsItemDiv" ).dialog({  title:'帳單明細' ,width: 600, resizable: true, modal: true  });
			
			$('#printBtn3').click(function() {
				window.print();
			});
			
			$('#closeBtn3').click(function() {
				$( "#paymentsItemDiv" ).dialog("close");
			});
		});
		//-->
		</script>
	</c:when>
	<c:otherwise>
		查無資料
		<script type="text/javascript">
		<!--
		$(document).ready(function() {
			$( "#paymentsItemDiv" ).dialog({  title:'帳單明細' ,width: 300, resizable: false, modal: true, buttons : {
				Ok : function() {
					$(this).dialog("close");
				}
			}  });
		});
		//-->
		</script>
	</c:otherwise>
</c:choose>